/*
 * ConfigurationForm.java
 *
 * Created on 21  2007, 02:41
 * Note: This source code is protected under the This software is licensed under the CC-GNU GPL.
 */
package OpenToday.GUI;

import OpenToday.IManager;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Spacer;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;


/**
 *
 * @author:  Menny Even Danan (c) 2007. Note: This source code is protected under the This software is licensed under the CC-GNU GPL.
 */
public class AboutForm extends Form implements CommandListener {

    private final IManager m_manager;

    public AboutForm(IManager manager, MIDlet app) {
        super("About");
        super.setTitle("About " + app.getAppProperty("MIDlet-Name"));

        m_manager = manager;
        //OKl command
        super.addCommand(new Command("OK", Command.OK, 0));
        super.setCommandListener(this);
        //building form
        AddString(app.getAppProperty("MIDlet-Name") + " v" + app.getAppProperty("MIDlet-Version"), true, true);
        AddString("deploy.counter " + app.getAppProperty("Deploymentcounter"), false, false);
        AddString(app.getAppProperty("MIDlet-Vendor") + " (c) 2009 under CC-GNU GPL.", false, false);
        AddString("", false, false);
        AddString(app.getAppProperty("MIDlet-Description"), false, false);
        AddString("", false, false);
        AddString("Latest version can be downloaded from " + app.getAppProperty("MIDlet-Info-URL"), false, false);
        AddString("", false, false);
        AddString("Thanks:", false, true);
        AddString("Joost206 for the icons.", false, false);
        AddString("Lasyk.net forums for support.", false, false);
    }

    private static Font getFont(boolean bold, boolean underlined) {
        int type = Font.STYLE_PLAIN;
        if (bold) {
            type += Font.STYLE_BOLD;
        }
        if (underlined) {
            type += Font.STYLE_UNDERLINED;
        }
        return Font.getFont(Font.FACE_PROPORTIONAL, type, Font.SIZE_SMALL);
    }

    private void AddSpacer() {
        super.append(new Spacer(1000, 1));
    }

    private void AddString(String text, boolean bold, boolean underlined) {
        StringItem line = new StringItem(null, text + "\n\r");
        line.setFont(getFont(bold, underlined));
        line.setLayout(StringItem.LAYOUT_LEFT + StringItem.LAYOUT_NEWLINE_AFTER);
        super.append(line);
    }

    public void commandAction(Command command, Displayable displayable) {
        if (command.getCommandType() == Command.OK) {
            // display main GUI
            m_manager.displayYourself();
        }
    }
}
